/**
 * 添加展期弹窗控制器
 */
import tem from './index.html'
import './index.less'
import $_fn from '~plugins'
class deferCtrl {
  constructor($scope,$rootScope,http,$ui,$state,$location,$timeout) {
    $scope.param = {}
    $scope.redErr = {}
    $scope.cancel = function () {
      $rootScope.$uiDirectiveModal.close() //关闭方法
    }
    console.log($scope.params)
    $scope.param1={
    	oid:$scope.params.id
    }
    //提交参数
    $scope.param2={}
    $scope.param3={}
    //获取订单信息
    $scope.xinXi=function(){
  	  		http.post('selectRenewalRead.do',$scope.param1,function (data) {
				if(data.errcode==1){
					$ui.toast({
						text:data.errmsg,
						type:'succeed',
						appendTo:'.defer'
					})
					$scope.order=data.data
					$scope.$apply()
				}else{
					$ui.toast({
						text:data.errmsg,
						type:'warning',
						appendTo:'.defer'
					})
				}
	        },function(_data){
	            console.log(_data);//报错
	      	})
  	  }
  	  $scope.xinXi()
  	  $scope.isShow=true;
  	  $scope.tiJiao1=function(){
  	  	$scope.isShow=false;
  	  	$scope.param2.oid=$scope.params.id;
    	$scope.param2.r_interest=$scope.order.interest;
    	$scope.param2.sumP=$scope.order.num;
    	$scope.param2.periods=$scope.order.periods;
    	$scope.param2.sumNumn=$scope.param3.yue+'期';
    	$scope.param2.sumNum=parseInt($scope.param3.yue)+parseInt($scope.order.num);
  	  	console.log('--------',$scope.param2.num);
  	  	console.log('-----------1',$scope.param2.periods)
  	  }
  	  //返回修改
  	  $scope.fanHui1=function(){
  	  	$scope.isShow=true;
  	  }
  	  $scope.tiJiao2=function(){
  	  	http.post('addRollover.do',$scope.param2,function (data) {
	        if(data.errcode==1){
					$ui.toast({
						text:data.errmsg,
						type:'succeed'
					})
					$scope.cancel()
				}else{
					$ui.toast({
						text:data.errmsg,
						type:'warning',
						appendTo:'.defers'
					})
				}
     	 })
  	  }
  	  
  	  
    /*$scope.tiJiao1=function () {
    	console.log('添加展期')
    	$scope.param2.oid=$scope.params.id;
    	$scope.param2.r_interest=$scope.order.interest;
    	$scope.param2.sumP=$scope.order.sumP;
    	$scope.param2.sumNumn=$scope.param3.yue+'期';
    	$scope.param2.sumNum=parseInt($scope.param3.yue)+parseInt($scope.order.sumP);
      	http.post('addRollover.do',$scope.param2,function (data) {
	        if(data.errcode == 1){
	        	
	          
	        }else{
	        }
     	 })
    }*/
  }
}


deferCtrl.$inject = ['$scope','$rootScope','http','$ui','$state','$location','$timeout','$interval']
module.exports = angular.module('directive.defer', []).directive('defer', function() {
  return {
    restrict: 'E',
    template: tem,
    replace:true,
    controller: deferCtrl,
    scope: {
      params: '<'
    },
    link:function(){
      $_fn.clickBind()
    }
  }
}).name